﻿CREATE PROCEDURE [dbo].[yaf_nntpforum_list](
                @BoardID     INT,
                @Minutes     INT  = NULL,
                @NntpForumID INT  = NULL,
                @Active      BIT  = NULL)
AS
    BEGIN
        SELECT   a.Name,
                 a.Address,
                 Port = Isnull(a.Port,119),
                 a.NntpServerID,
                 b.NntpForumID,
                 b.GroupName,
                 b.ForumID,
                 b.LastMessageNo,
                 b.LastUpdate,
                 b.Active,
                 ForumName = c.Name
        FROM     yaf_NntpServer a
                 JOIN yaf_NntpForum b
                   ON b.NntpServerID = a.NntpServerID
                 JOIN yaf_Forum c
                   ON c.ForumID = b.ForumID
        WHERE    (@Minutes IS NULL 
          OR Datediff(n,b.LastUpdate,Getdate()) > @Minutes)
        AND (@NntpForumID IS NULL 
              OR b.NntpForumID = @NntpForumID)
        AND a.BoardID = @BoardID
        AND (@Active IS NULL 
              OR b.Active = @Active)
        ORDER BY a.Name,
                 b.GroupName
    END


